package leetcode.editor.cn;

import java.util.HashMap;
import java.util.HashSet;

/**
题目名字---:统计出现过一次的公共字符串
题目编号---:2085	
解题时间---:2021-12-03 18:16:05
*/

public class CountCommonWordsWithOneOccurrence{
    public static void main(String[] args) {
        Solution solution = new CountCommonWordsWithOneOccurrence().new Solution();    
    }
    
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int countWords(String[] words1, String[] words2) {
        HashMap<String, Integer> hashMap = new HashMap<>();
        HashMap<String, Integer> hashMap2 = new HashMap<>();
        for (String s : words1) {
            if (hashMap.containsKey(s)) {
                hashMap.put(s,hashMap.get(s)+1);
            }else {
                hashMap.put(s,1);
            }
        }
        for (String s : words2) {
            if (hashMap2.containsKey(s)) {
                hashMap2.put(s,hashMap2.get(s)+1);
            }else {
                hashMap2.put(s,1);
            }
        }
        int count =0;
        for (String s : hashMap.keySet()) {
            Integer i = hashMap.getOrDefault(s,0);
            Integer j = hashMap2.getOrDefault(s, 0);
            if (i==1&&j==1) {
                count++;
            }
        }
        return count;
    }
}
//leetcode submit region end(Prohibit modification and deletion)


}